package com.interview.three;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.lang.ref.Cleaner;

/**
 * Cleaner 原理都类似，有个守护线程去处理
 */
@Slf4j
public class TestClear {
    public static void main(String[] args) throws IOException {
        Cleaner cleaner = Cleaner.create();
        cleaner.register(new MyResource(),()->log.info("调用清除方法1"));
        cleaner.register(new MyResource(),()->log.info("调用清除方法2"));
        cleaner.register(new MyResource(),()->log.info("调用清除方法2"));
        System.gc();
        System.in.read();
    }
    static class MyResource{
        
    }
}
